package com.blb.marry.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.blb.marry.entity.Hotel;
import com.blb.marry.entity.Information;
import com.blb.marry.entity.Package;
import com.blb.marry.entity.Room;
import com.blb.marry.service.HotelService;
import com.blb.marry.service.InformationService;
import com.blb.marry.service.PackageService;
import com.blb.marry.service.RoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @author lvtian
 * @date 2023/1/16 13:35
 */
@Controller
public class RoomController {
    @Autowired
    private RoomService roomService;
    @Autowired
    private PackageService packageService;
    @Autowired
    private InformationService informationService;
    @Autowired
    private HotelService hotelService;

    @RequestMapping("/getRoomById")
    public String getRoomById(Long hotelId , Model model) {
        System.out.println(hotelId);
        //酒店信息
        Hotel hotel = hotelService.getHotel(hotelId);
//        System.out.println(hotel);
        //房间信息
        List<Room> rooms= roomService.getRoomById(hotelId);
//        rooms.forEach(room -> {
//            System.out.println(room);
//        });
        //套餐信息
        List<Package> packages = packageService.getPackageById(hotelId);
        //info信息
        List<Information> Infos = informationService.list(new QueryWrapper<Information>().lambda().eq(Information::getTbHotelHotelId, hotelId));
        Information info = Infos.get(0);
        model.addAttribute("hotel",hotel);
        model.addAttribute("rooms",rooms);
        model.addAttribute("packages",packages);
        model.addAttribute("info",info);
        return "forward:/details.html";
    }
}
